package zero.tech.games.extension.service;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import zero.tech.games.common.topic.ProxyAdd;
import zero.tech.games.common.topic.ProxyRebind;
import zero.tech.games.extension.mapper.ClubMemberProxyMapper;
import zero.tech.games.extension.service.api.IExtensionService;
import zero.tech.games.extension.util.ExtensionUtil;

@Service
public class ExtensionServiceImpl implements IExtensionService{
	private static final Logger  logger=LoggerFactory.getLogger(ExtensionServiceImpl.class);
	@Autowired
	private ClubMemberProxyMapper clubMemberProxyMapper;
	@Autowired
	private ExtensionUtil extensionUtil;
	@Override
	public void serverInit() {
		logger.error("准备开始计算无限代人数---------------");
		long now = System.currentTimeMillis();
		List<ProxyAdd> proxyAdds = clubMemberProxyMapper.findAllClubProxys();
		logger.error("数据库查询关系耗时:{}",(System.currentTimeMillis()-now));
		now=System.currentTimeMillis();
		extensionUtil.toBeTree(proxyAdds);
		logger.error("内存关系树耗时:{}",(System.currentTimeMillis()-now));
	}
	
	
	
	
	@Override
	public List<Integer> getZsSubIds(int club_id,int uid) {
		return extensionUtil.getZsSubIds(club_id,uid);
	}
	@Override
	public List<Integer> getFzsSubIds(int club_id,int uid) {
		return extensionUtil.getFzsSubIds(club_id, uid);
	}
	@Override
	public List<Integer> getAllSubIds(int club_id,int uid) {
		return extensionUtil.getAllSubIds(club_id, uid);
	}
	@Override
	public List<Integer> getParentIds(int club_id, int uid) {
		return extensionUtil.getParentIds(club_id, uid);
	}

	@Override
	public void proxyAddDynamic(ProxyAdd proxyAdd) {
		extensionUtil.proxyAddDynamic(proxyAdd.getClub_id(),proxyAdd.getUid(),proxyAdd.getFather_uid());
	}




	@Override
	public void proxyAddDynamic(ProxyRebind proxyRebind) {
		extensionUtil.proxyRebindDynamic(proxyRebind.getClub_id(),proxyRebind.getUid(),proxyRebind.getFather_uid());
	}
	
}
